<%@ Page language="vb" CodeFile="editInvoiceCredit.aspx.vb" Inherits="editInvoiceCredit_aspx_vb" %>

<%
    If (Request.QueryString("do")) = Nothing Then 
        invoiceCreditID = Request.QueryString("invoiceCreditID")
        invoiceCreditID = CLng(invoiceCreditID)
        dbOpen()
        RecSet = Conn.Execute("Select i.invoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.paymentDate, i.paymentTerm, i.invoiceRecord, i.paymentRecord, i.invoiceSettled, i.invoicePrinted, i.date AS tblInvoiceDate, co.country, co.countryCode, co.countryCurrency, co.decimals, p.partnerName, p.street, p.zipcode, p.city, p.date AS tblPartnerDate, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = i.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax From ((tblInvoiceCredit i INNER JOIN tblCountry co ON co.countryID = i.countryID) INNER JOIN tblPartner p ON p.partnerID = i.partnerID) Where i.invoiceCreditID = " & invoiceCreditID & "")
        If RecSet.EOF Then 
            Response.Redirect("searchInvoice.aspx")
        Else
            invoiceID = RecSet.Fields("invoiceID").Value
            invoiceAmount = RecSet.Fields("invoiceAmount").Value
            invoiceClaim = RecSet.Fields("invoiceClaim").Value
            invoiceDate = RecSet.Fields("invoiceDate").Value
            expiryDate = RecSet.Fields("expiryDate").Value
            paymentDate = RecSet.Fields("paymentDate").Value
            paymentTerm = RecSet.Fields("paymentTerm").Value
            invoiceRecord = RecSet.Fields("invoiceRecord").Value
            paymentRecord = RecSet.Fields("paymentRecord").Value
            invoiceSettled = RecSet.Fields("invoiceSettled").Value
            invoicePrinted = RecSet.Fields("invoicePrinted").Value
            tblInvoiceDate = RecSet.Fields("tblInvoiceDate").Value
            country = RecSet.Fields("country").Value
            countryCode = RecSet.Fields("countryCode").Value
            countryCurrency = RecSet.Fields("countryCurrency").Value
            decimals = RecSet.Fields("decimals").Value
            partnerName = RecSet.Fields("partnerName").Value
            street = RecSet.Fields("street").Value
            zipcode = RecSet.Fields("zipcode").Value
            city = RecSet.Fields("city").Value
            tblPartnerDate = RecSet.Fields("tblPartnerDate").Value
            salesTax = RecSet.Fields("salesTax").Value
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        If IsDBNull(salesTax) = true Then 
            dbOpen()
            RecSet = Conn.Execute("select Top 1 st.salesTax From (tblInvoiceCredit i INNER JOIN tblSalesTax st ON st.countryID = i.countryID) Where i.invoiceID = " & invoiceID & " Order By st.date Desc")
            If Not RecSet.EOF Then 
                salesTax = RecSet.Fields("salesTax").Value
            End IF
            RecSet.Close()
            RecSet = Nothing
            dbClose()
        End IF
        If IsDBNull(invoiceDate) Then 
            invoiceStatus = "not activated"
        ElseIf CDbl(invoicePrinted) = 0 Then 
            invoiceStatus = "queued for printing"
        ElseIf CDbl(invoicePrinted) = 1 Then 
            invoiceStatus = "printed"
        ElseIf CDbl(invoiceSettled) = 1 Then 
            invoiceStatus = "settled"
        End IF
        If IsDBNull(invoiceDate) Then 
            invoiceDate = "N/A"
        End IF
        If IsDBNull(expiryDate) Then 
            expiryDate = "N/A"
        ElseIf DateDiff("d", Convert.ToDateTime(expiryDate), Convert.ToDateTime(__date)) <= 0 And CDbl(invoiceSettled) = 0 Then 
            expiryDate = "<font color='red'>" & expiryDate & "</font>"
        ElseIf CDbl(invoiceSettled) = 1 Then 
            paymentDate = "<font color='green'>" & paymentDate & "</font>"
        End IF
        If IsDBNull(paymentDate) Then 
            paymentDate = "N/A"
        End IF
        salesTaxAmount = 0
        salesTaxAmount = (CDbl(invoiceAmount) * CDbl(salesTax)) / 100
        invoiceAmountSalesTax = CDbl(invoiceAmount) + salesTaxAmount
        invoiceAmountSalesTax = FormatNumber(CDbl(invoiceAmountSalesTax), decimals)
        Over()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='1000'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr>")
        Response.Write("<td class='headline' colspan='3'>")
        Response.Write("INVOICE DETAILS FOR CREDIT INVOICE ID " & invoiceCreditID & "")
        If Len(invoiceDate) > 0 And CDbl(invoicePrinted) = 0 And Len(paymentDate) > 0 And CDbl(paymentRecord) = 0 Then 
            Response.Write("&nbsp; <a href='editInvoiceCredit.aspx?invoiceCreditID=" & invoiceCreditID & "&do=form'>[EDIT]</a>")
        End IF
        If Not CStr(invoiceDate) = "N/A" Then 
            Response.Write("&nbsp; <a href='printInvoice.aspx?invoiceCreditID=" & invoiceCreditID & "' target='_blank'>[PRINT]</a>")
        End IF
        Response.Write("<hr class='hrHeadline'>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("<tr><td class='formBold'>Invoice ID:</td><td align='right'>" & invoiceCreditID & "</td></tr>")
        Response.Write("<tr><td class='formBold'>References invoice ID:</td><td align='right'>" & invoiceID & "</td></tr>")
        Response.Write("<tr><td class='formBold'>Invoice status:</td><td align='right'>" & invoiceStatus & "</td></tr>")
        Response.Write("<tr><td class='formBold'>Invoice date:</td><td align='right'>" & invoiceDate & "</td></tr>")
        Response.Write("<tr><td class='formBold'>Expiry date:</td><td align='right'>" & expiryDate & "</td></tr>")
        Response.Write("<tr><td class='formBold'>Payment date:</td><td align='right'>" & paymentDate & "</td></tr>")
        Response.Write("<tr><td class='formBold'>Payment term (days):</td><td align='right'>" & paymentTerm & "</td></tr>")
        Response.Write("<tr><td class='formBold'>Invoice amount VAT incl. (" & countryCurrency & "):</td><td align='right'>" & FormatNumber(CDbl(invoiceAmountSalesTax), 2) & "</td></tr>")
        Response.Write("<tr><td class='formBold'>Invoice amount VAT excl. (" & countryCurrency & "):</td><td align='right'>" & FormatNumber(CDbl(invoiceAmount), 2) & "</td></tr>")
        Response.Write("<tr><td class='formBold'>Claim amount VAT excl. (" & countryCurrency & "):</td><td align='right'>" & FormatNumber(CDbl(invoiceClaim), 2) & "</td></tr>")
        Response.Write("<tr><td class='formBold'>First created:</td><td align='right'>" & Left(tblInvoiceDate, 10) & "</td></tr>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("<td width='100'></td>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='2'>PAYEE - PARTNER<hr class='hrHeadline'></td></tr>")
        Response.Write("<tr><td class='formBold'>Partner:</td><td align='right'>" & partnerName & "</td></tr>")
        Response.Write("<tr><td class='formBold'>Country:</td><td align='right'>" & country & "</td></tr>")
        Response.Write("<tr><td class='formBold'>Street:</td><td align='right'>" & street & "</td></tr>")
        Response.Write("<tr><td class='formBold'>Zipcode:</td><td align='right'>" & countryCode & "-" & zipcode & "</td></tr>")
        Response.Write("<tr><td class='formBold'>City:</td><td align='right'>" & city & "</td></tr>")
        Response.Write("<tr><td class='formBold'>Country:</td><td align='right'>" & country & "</td></tr>")
        Response.Write("<tr><td class='formBold'>First created:</td><td align='right'>" & Left(tblPartnerDate, 10) & "</td></tr>")
        Response.Write("<tr><td colspan='2'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("<tr><td><br></td></tr>")
        Response.Write("<tr>")
        Response.Write("<td valign='top' colspan='3'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='1000'>")
        Response.Write("<tr><td class='headline' colspan='10'>THIS INVOICE CONTAINS THE FOLLOWING VEHICLES<hr class='hrHeadline'></td></tr>")
        dbOpen()
        RecSet = Conn.Execute("Select ic.leaseCurrentDate, ic.invoiceID, v.vehicleID, v.regnr, v.vinNumber, v.contractNumber, v.date, p.product, pl.price, b.brand, m.model, d.dealer From ((((((tblInvoiceCreditContent ic INNER JOIN tblVehicle v ON v.vehicleID = ic.vehicleID) INNER JOIN tblProduct p ON p.productID = v.productID) INNER JOIN tblPriceList pl ON pl.priceListID = v.priceListID) INNER JOIN tblBrand b ON b.brandID = v.brandID) INNER JOIN tblModel m ON m.modelID = v.modelID) INNER JOIN tblDealer d ON d.dealerID = v.dealerID) Where ic.invoiceCreditID = " & invoiceCreditID & "")
        If RecSet.EOF Then 
            Response.Write("<tr><td><font color='red'>ERROR</font></td></tr>")
        Else
            Response.Write("<tr bgcolor='#eeeeee'>")
            Response.Write("<td class='formBold'>Car dealer</td>")
            Response.Write("<td class='formBold'>Contract number</td>")
            Response.Write("<td class='formBold'>Licence number</td>")
            Response.Write("<td class='formBold'>VIN-number</td>")
            Response.Write("<td class='formBold'>Product</td>")
            Response.Write("<td class='formBold'>Price (" & countryCurrency & ")</td>")
            Response.Write("<td class='formBold'>Period</td>")
            Response.Write("<td class='formBold'>InvoiceID</td>")
            Response.Write("<td class='formBold'>First created</td>")
            Response.Write("<td class='formBold'></td>")
            Response.Write("</tr>")
            rowNumber = 1
            Do Until RecSet.EOF
                leaseCurrentDate = RecSet.Fields("leaseCurrentDate").Value
                invoiceID = RecSet.Fields("invoiceID").Value
                vehicleID = RecSet.Fields("vehicleID").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                contractNumber = RecSet.Fields("contractNumber").Value
                __date = RecSet.Fields("date").Value
                product = RecSet.Fields("product").Value
                price = RecSet.Fields("price").Value
                brand = RecSet.Fields("brand").Value
                model = RecSet.Fields("model").Value
                dealer = RecSet.Fields("dealer").Value
                leaseCurrentDate = Left(leaseCurrentDate, 7)
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & dealer & "</td>")
                Response.Write("<td>" & contractNumber & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td>" & product & "</td>")
                Response.Write("<td align='right'>- " & FormatNumber(CDbl(price), 2) & "</td>")
                Response.Write("<td>" & leaseCurrentDate & "</td>")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td>" & Left(__date, 10) & "</td>")
                Response.Write("<td><a href='editVehicle.aspx?vehicleID=" & vehicleID & "'>view details</a></td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr><td colspan='10'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    ElseIf Request.QueryString("do") = "form" Then 
        subDo = Request.QueryString("subDo")
        invoiceCreditID = Request.QueryString("invoiceCreditID")
        invoiceCreditID = CLng(invoiceCreditID)
        realTime = Now()
        year = Left(realTime, 4)
        year = year - CStr(1)
        dbOpen()
        RecSet = Conn.Execute("Select i.invoiceDate, i.paymentDate, i.paymentTerm, i.invoiceRecord, i.paymentRecord, i.invoicePrinted From tblInvoiceCredit i Where i.invoiceCreditID = " & invoiceCreditID & "")
        If RecSet.EOF Then 
            Response.Redirect("searchInvoice.aspx")
        Else
            invoiceDate = RecSet.Fields("invoiceDate").Value
            paymentDate = RecSet.Fields("paymentDate").Value
            paymentTerm = RecSet.Fields("paymentTerm").Value
            invoiceRecord = RecSet.Fields("invoiceRecord").Value
            paymentRecord = RecSet.Fields("paymentRecord").Value
            invoicePrinted = RecSet.Fields("invoicePrinted").Value
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Over()
        strJS = ""
        If Len(invoiceDate) > 0 And CDbl(invoicePrinted) = 0 Then 
            strJS = strJS + "[""invoiceDateYear"", ""<1""],"
            strJS = strJS + "[""invoiceDateMonth"", ""<1""],"
            strJS = strJS + "[""invoiceDateDay"", ""<1""],"
        End IF
        If Len(paymentDate) > 0 And CDbl(paymentRecord) = 0 Then 
            strJS = strJS + "[""paymentDateYear"", ""<1""],"
            strJS = strJS + "[""paymentDateMonth"", ""<1""],"
            strJS = strJS + "[""paymentDateDay"", ""<1""],"
        End IF
        If CDbl(invoicePrinted) = 0 Then 
            strJS = strJS + "[""paymentTerm"", ""==''""],"
        End IF
        If Len(strJS) > 0 Then 
            strJS = Left(strJS, Len(strJS) - 1)
            checkFields()
        End IF
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='1000'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='3'>EDIT CREDIT INVOICE ID " & invoiceCreditID & "<font color='#fcbc00'>" & subDo & "</font><hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='editInvoice.aspx?do=save&invoiceCreditID=" & invoiceCreditID & "' method='post' onsubmit=""javascript:return checkFields();"">")
        If Len(invoiceDate) > 0 And CDbl(invoicePrinted) = 0 Then 
            Response.Write("<tr>")
            Response.Write("<td class='formBold'>Invoice date:&nbsp; </td>")
            Response.Write("<td align='right'>")
            Response.Write("<select name='invoiceDateYear' id='invoiceDateYear'>")
            Response.Write("<option value=''>&nbsp; Year ")
            stopYear = CDbl(year) + 4
            yearCounter = year
            For yearLoop = year To stopYear
                Response.Write("<option value='" & yearCounter & "'")
                If CLng(yearCounter) = CLng(Left(invoiceDate, 4)) Then 
                    Response.Write("selected='selected'")
                End IF
                Response.Write("> " & yearCounter & " ")
                yearCounter = yearCounter + 1
            Next
            Response.Write("</select>")
            Response.Write(" - ")
            Response.Write("<select name='invoiceDateMonth' id='invoiceDateMonth'>")
            Response.Write("<option value=''>&nbsp; Month ")
            yearCounter = 1
            For yearLoop = 1 To 12
                Response.Write("<option value='" & yearCounter & "'")
                If CLng(yearCounter) = CLng(Mid(invoiceDate, 6, 2)) Then 
                    Response.Write("selected='selected'")
                End IF
                Response.Write("> " & yearCounter & " ")
                yearCounter = yearCounter + 1
            Next
            Response.Write("</select>")
            Response.Write(" - ")
            Response.Write("<select name='invoiceDateDay' id='invoiceDateDay'>")
            Response.Write("<option value=''>&nbsp; Day&nbsp; ")
            yearCounter = 1
            For yearLoop = 1 To 31
                Response.Write("<option value='" & yearCounter & "'")
                If CLng(yearCounter) = CLng(Right(invoiceDate, 2)) Then 
                    Response.Write("selected='selected'")
                End IF
                Response.Write("> " & yearCounter & " ")
                yearCounter = yearCounter + 1
            Next
            Response.Write("</select>")
            Response.Write("</td>")
            Response.Write("<td>")
            Response.Write("<div id='error_invoiceDateYear' class='edit_error'>&laquo; OBS!<br></div>")
            Response.Write("<div id='error_invoiceDateMonth' class='edit_error'>&laquo; OBS!<br></div>")
            Response.Write("<div id='error_invoiceDateDay' class='edit_error'>&laquo; OBS!<br></div>")
            Response.Write("</td>")
            Response.Write("</tr>")
        End IF
        If Len(paymentDate) > 0 And CDbl(paymentRecord) = 0 Then 
            Response.Write("<tr>")
            Response.Write("<td class='formBold'>Payment date:&nbsp; </td>")
            Response.Write("<td align='right'>")
            Response.Write("<select name='paymentDateYear' id='paymentDateYear'>")
            Response.Write("<option value=''>&nbsp; Year ")
            stopYear = CDbl(year) + 4
            yearCounter = year
            For yearLoop = year To stopYear
                Response.Write("<option value='" & yearCounter & "'")
                If CLng(yearCounter) = CLng(Left(paymentDate, 4)) Then 
                    Response.Write("selected='selected'")
                End IF
                Response.Write("> " & yearCounter & " ")
                yearCounter = yearCounter + 1
            Next
            Response.Write("</select>")
            Response.Write(" - ")
            Response.Write("<select name='paymentDateMonth' id='paymentDateMonth'>")
            Response.Write("<option value=''>&nbsp; Month ")
            yearCounter = 1
            For yearLoop = 1 To 12
                Response.Write("<option value='" & yearCounter & "'")
                If CLng(yearCounter) = CLng(Mid(paymentDate, 6, 2)) Then 
                    Response.Write("selected='selected'")
                End IF
                Response.Write("> " & yearCounter & " ")
                yearCounter = yearCounter + 1
            Next
            Response.Write("</select>")
            Response.Write(" - ")
            Response.Write("<select name='paymentDateDay' id='paymentDateDay'>")
            Response.Write("<option value=''>&nbsp; Day&nbsp; ")
            yearCounter = 1
            For yearLoop = 1 To 31
                Response.Write("<option value='" & yearCounter & "'")
                If CLng(yearCounter) = CLng(Right(paymentDate, 2)) Then 
                    Response.Write("selected='selected'")
                End IF
                Response.Write("> " & yearCounter & " ")
                yearCounter = yearCounter + 1
            Next
            Response.Write("</select>")
            Response.Write("</td>")
            Response.Write("<td>")
            Response.Write("<div id='error_paymentDateYear' class='edit_error'>&laquo; OBS!<br></div>")
            Response.Write("<div id='error_paymentDateMonth' class='edit_error'>&laquo; OBS!<br></div>")
            Response.Write("<div id='error_paymentDateDay' class='edit_error'>&laquo; OBS!<br></div>")
            Response.Write("</td>")
            Response.Write("</tr>")
        End IF
        If CDbl(invoicePrinted) = 0 Then 
            Response.Write("<tr><td class='formBold'>Payment term (days):</td><td align='right'><input type='text' name='paymentTerm' id='paymentTerm' value='" & paymentTerm & "' size='40' maxlength='50' onkeyup='re=/(\d*)/; re.exec(this.value); this.value=RegExp.$1;'></td><td><div id='error_paymentTerm' class='edit_error'>&laquo; OBS!</div></td></tr>")
        End IF
        Response.Write("<tr>")
        Response.Write("<td align='right' colspan='2'>")
        Response.Write("<input type='reset' value='Reset'>")
        Response.Write("<input type='submit' value='Save changes'>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("<td width='100'></td>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
    ElseIf Request.QueryString("do") = "save" Then 
        invoiceCreditID = Request.QueryString("invoiceCreditID")
        invoiceDateDay = Request.Form("invoiceDateDay")
        invoiceDateMonth = Request.Form("invoiceDateMonth")
        invoiceDateYear = Request.Form("invoiceDateYear")
        paymentDateYear = Request.Form("paymentDateYear")
        paymentDateMonth = Request.Form("paymentDateMonth")
        paymentDateDay = Request.Form("paymentDateDay")
        paymentTerm = Request.Form("paymentTerm")
        invoiceCreditID = CLng(invoiceCreditID)
        If Len(invoiceDateDay) > 0 And Len(invoiceDateMonth) > 0 And Len(invoiceDateYear) > 0 Then 
            invoiceDateYear = CLng(invoiceDateYear)
            invoiceDateMonth = CLng(invoiceDateMonth)
            invoiceDateDay = CLng(invoiceDateDay)
            If CLng(invoiceDateMonth) < 10 Then 
                invoiceDateMonth = "0" & invoiceDateMonth & ""
            End IF
            If CLng(invoiceDateDay) < 10 Then 
                invoiceDateDay = "0" & invoiceDateDay & ""
            End IF
            invoiceDate = invoiceDateYear & "-" & invoiceDateMonth & "-" & invoiceDateDay
            If IsDate(invoiceDate) Then 
                dbOpen()
                Conn.Execute("Update tblInvoiceCredit Set invoiceDate = '" & invoiceDate & "' Where invoiceCreditID = " & invoiceCreditID & "")
                dbClose()
            End IF
        End IF
        If Len(paymentDateDay) > 0 And Len(paymentDateMonth) > 0 And Len(paymentDateYear) > 0 Then 
            paymentDateYear = CLng(paymentDateYear)
            paymentDateMonth = CLng(paymentDateMonth)
            paymentDateDay = CLng(paymentDateDay)
            If CLng(paymentDateMonth) < 10 Then 
                paymentDateMonth = "0" & paymentDateMonth & ""
            End IF
            If CLng(paymentDateDay) < 10 Then 
                paymentDateDay = "0" & paymentDateDay & ""
            End IF
            paymentDate = paymentDateYear & "-" & paymentDateMonth & "-" & paymentDateDay
            If IsDate(paymentDate) Then 
                dbOpen()
                Conn.Execute("Update tblInvoiceCredit Set paymentDate = '" & paymentDate & "' Where invoiceCreditID = " & invoiceCreditID & "")
                dbClose()
            End IF
        End IF
        If Len(paymentTerm) > 0 Then 
            paymentTerm = CLng(paymentTerm)
            dbOpen()
            Conn.Execute("Update tblInvoiceCredit Set paymentTerm = " & paymentTerm & " Where invoiceCreditID = " & invoiceCreditID & "")
            dbClose()
            dbOpen()
            RecSet = Conn.Execute("Select invoiceDate From tblInvoiceCredit Where invoiceCreditID = " & invoiceCreditID & "")
            invoiceDate = RecSet.Fields("invoiceDate").Value
            RecSet.Close()
            RecSet = Nothing
            dbClose()
            If Len(invoiceDate) > 0 Then 
                expiryDate = DateAdd("d", CDbl(paymentTerm), Convert.ToDateTime(invoiceDate))
                dbOpen()
                Conn.Execute("Update tblInvoiceCredit Set expiryDate = '" & expiryDate & "' Where invoiceCreditID = " & invoiceCreditID & "")
                dbClose()
            End IF
        End IF
        Response.Redirect("editInvoice.aspx?subDo=%20-%20SAVED&do=form&invoiceCreditID=" & invoiceCreditID & "")
    End IF
%>
